package com.ykq.controller;

import com.ykq.entity.Staff;
import com.ykq.service.StaffService;
import com.ykq.vo.LoginVO;
import com.ykq.vo.R;
import com.ykq.vo.StaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: 闫克起
 * @Description:
 * @Date: Create in 9:38 2024/10/21
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;
    @PostMapping("/login")
    public R login(@RequestBody LoginVO loginVO){
        return staffService.selectByNameAndPwd(loginVO);
    }

    @GetMapping("/getCurrentUser")
    public R getCurrentUser(HttpSession session){
        Object staff = session.getAttribute("staff");
        return R.ok(staff);
    }

    @GetMapping("/logout")
    public R logout(HttpSession session){
        session.removeAttribute("staff");
        return R.ok();
    }

    @PostMapping("/list")
    public R list(Integer current,Integer pageSize,@RequestBody StaffVo staffVo){
        return staffService.selectByCondition(current,pageSize,staffVo);
    }

    @GetMapping("/checkStaffid")
    public R checkStaffid(Integer staffid){
        return staffService.checkStaffid(staffid);
    }

    @PostMapping("/add")
    public R add(@RequestBody Staff staff){
        return staffService.add(staff);
    }
}
